#include "comm.h"

int main()
{
    char *buf;
    int i = 1;
    int shmid = create_shm(1024),current_shmid;// 创建共享内存块
	
	if(shmid < 0){
		return shmid;
	}

	buf = shmat(shmid,NULL, 0 );
	if ( (int)buf == -1 )
	{
		perror("shmat addr error") ;
		return -1 ;
	}

    while(1)
    {
		current_shmid = get_shmid(1024);
		if(current_shmid!=shmid)
		{
			buf = shmat(current_shmid,NULL, 0 );
			if ( (int)buf == -1 )
			{
				perror("shmat addr error") ;
				return -1 ;
			}
			shmid = current_shmid;
		}
        buf[i] = '@'+i ;
		buf[0] = i;
        i++;
        sleep(1); 
        if(i == 27)
            break; // 让程序结束，去释放该共享内存
    }
	destroy_shm(get_shmid());
    return 0;
}